<?php
/* 
 * class.index.php
 * 我的百宝箱首页
 * @author samuel
 * @date 2009-05-29
 */
include_once 'class.myshopBase.php';
class myshop_index extends myshopBase {

    function  __construct($core) {
        parent::__construct();
        //参数处理
        $this->step = $this->params['step'] ? strtolower(trim($core->params['step'])) : 'index';
	    $this->user_id = $this->params['uid'] ? (int)$this->params['uid'] : 0;
	    $this->type = $this->params['type'] ? strtolower(trim($this->params['type'])) : 'all';
        $this->page = $this->params['page'] ? (int)$this->params['page'] : 1;
        $this->cid = $this->params['cid'] ? (int)$this->params['cid'] : 1;
        $this->aid = $this->params['aid'] ? (int)$this->params['aid'] : 1;
	    if(!$this->user_id){
		    $this->error = "用户ID不合法！";
		    $this->jumpError();
		    exit;
	    }

        $run = "run_" . $this->step;
        
        //header("Content-type: text/vnd.wap.wml");
        $this->$run();
    }

    function run_index(){
    	//WAP页面
	    //header("Content-type: text/vnd.wap.wml");
	    //TITLE
	    $page_title = "我的百宝箱-优惠券";
	    $content = "";
	
	    $tickets = $this->getUserTicket('', $this->user_id);
	    $arr_ticket_cates = array();
	    //var_dump($tickets);
        if($tickets){
            $arr_seller_id = array();
            $seller_ids = "";
            foreach($tickets as $ticket){
                $arr_seller_id[] = $ticket['SellerID'];   
            }
            $seller_ids = @implode(',', $arr_seller_id);
            //获取不同商家分类
            $distinct = array('table'=>'fun_seller_class', 'field'=>'SellerClassID', 'id'=>'SellerClassID', 'name'=>'SellerClassName');
            $cates = $this->getDistinctSellerCate($seller_ids, $distinct);
            if($cates){
                foreach($cates as $cate){
                    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=class&amp;cid=".$cate['SellerClassID']."'>".$cate['SellerClassName']."</a>|";
                }
            }
            $content .= "<br/>";
            //获取不同商家地区
            $distinct = array('table'=>'fun_seller_area', 'field'=>'SellerAreaID', 'id'=>'SellerAreaID', 'name'=>'SellerAreaNameCN');
            $cates = $this->getDistinctSellerCate($seller_ids, $distinct);
            if($cates){
                foreach($cates as $cate){
                    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=area&amp;aid=".$cate['SellerAreaID']."'>".$cate['SellerAreaNameCN']."</a>|";
                }
            }
            $content .= "<br/>";
            //获取不同商家商圈
            $distinct = array('table'=>'fun_seller_cbd', 'field'=>'SellerCBDID', 'id'=>'SellerCBDID', 'name'=>'SellerCBDNameCN');
            $cates = $this->getDistinctSellerCate($seller_ids, $distinct);
            if($cates){
                foreach($cates as $cate){
                    $content .= "<a href='".$_SERVER['PHP_SELF']."?uid=".$this->user_id."&amp;type=cbd&amp;cid=".$cate['SellerCBDID']."'>".$cate['SellerCBDNameCN']."</a>|";
                }
            }
            $content .= "<br/>";
        }
        
        $content .= "<input type='text' name='friend_mobile' value='' maxlength='20' size='15' />";
        $content .= "<anchor title=\"搜\">搜<go href=\"".$posturl."\" method=\"post\">
                        <postfield name=\"type\" value=\"friend\" />
                        <postfield name=\"friend_mobile\" value=\"$(friend_mobile)\" />
                        </go></anchor><br/><br/>";

        $content .= "<a href=''>收藏</a>|<a href=''>最新</a><br/>";
        
        if($tickets){
            foreach($tickets as $ticket){
                $content .= "<a href='".$_SERVER['PHP_SELF']."?act=ticket&amp;step=showinfo&amp;uid=".$this->user_id."&amp;tid=".$ticket['TicketID']."'>".$ticket['TicketMsg']."</a><br/>";
            }
        }

        $content .= "<br/>";
        

	
	
	
	
	    $content .= "<br/><br/>";
	    $content .= "<a href='' alt='建议帮助'>建议帮助</a>";



	    $this->core->tpl->assign('content', $content);
	    $this->core->tpl->assign('page_title', $page_title);
	    $this->core->tpl->display('comm.wml');
    
    }
}


?>
